package com.allwees.bs.module.ums.rest;

import com.allwees.bs.module.core.annotation.PrintLog;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.allwees.bs.core.modelbase.vo.R;
import com.allwees.bs.module.core.rest.BoCrudApi;
import com.allwees.bs.module.ums.entity.Customer;
import com.allwees.bs.module.ums.req.CustomerUpdateInfluencerReq;
import com.allwees.bs.module.ums.req.CustomerUpdatePromCodeReq;
import com.allwees.bs.module.ums.req.CustomerUpdateShareCodeReq;
import com.allwees.bs.module.ums.req.query.CustomerQueryReq;
import com.allwees.bs.module.ums.service.CustomerService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;


@PrintLog
@RestController
@RequestMapping("/backstage/api/ums/customer")
public class CustomerApi extends BoCrudApi<Customer, CustomerService> {

    @GetMapping("/page")
    public R page(Page<Customer> page, CustomerQueryReq req) {
        Page<Customer> page1 = boService.page(page, req);
        return R.ok(page1);
    }

    @PostMapping("/{uuid}/disable")
    @Override
    public R disable(@PathVariable String uuid) {
        boService.disable(uuid);
        return R.ok();
    }

    /**
     * 设置网红或归属人
     * @param uuid
     * @param req
     * @return
     */
    @PostMapping("/{uuid}/set_Influencer_and_belongName")
    public R setInfluencerAndBelongName(@PathVariable String uuid, @RequestBody CustomerUpdateInfluencerReq req) {
        boService.setInfluencerAndBelongName(uuid,req);
        return R.ok();
    }

    @GetMapping("/getBelongNameList")
    public R getBelongNameList() {
        List<String> belongNameList = new ArrayList<>();
        belongNameList.add("陈瑶");
        belongNameList.add("方佳");
        belongNameList.add("吕敏霞");
        belongNameList.add("徐冰冰");
        belongNameList.add("叶捷");
        belongNameList.add("赵虹雨");
        return R.ok(belongNameList);
    }

    @PostMapping("/{uuid}/enable")
    @Override
    public R enable(@PathVariable String uuid) {
        boService.enable(uuid);
        return R.ok();
    }

    @PostMapping("/save")
    public R save(@RequestBody Customer customer) {

        return R.ok(customer);
    }

    @PostMapping("/update-sharecode")
    public R updateShareCode(@RequestBody CustomerUpdateShareCodeReq req) {
        boService.updateShareCode(req);
        return R.ok();
    }

    @Deprecated
    @PostMapping("/update-promocode")
    public R updatePromoCode(@RequestBody CustomerUpdatePromCodeReq req) {
        boService.updatePromoCode(req);
        return R.ok();
    }

    @GetMapping("/refresh/promocode/{count}")
    public R refreshPromoCode(@PathVariable int count) {
        boService.refreshPromoCode(count);
        return R.ok();
    }
}
